<?php
namespace App\Controller;


class IndexController extends BaseController
{
    public function index()
    {
        R("App/User/oauthLogin");

        $config = D("Config")->getConfig();
        $config["delivery_time"] = json_encode(explode(',', $config["delivery_time"]));
        $this->assign("name", $config["name"]);
        $config = json_encode($config);
        $this->assign("config", $config);

        $menu = D("Menu")->getMenuTreeList(array(), true, "rank desc,id desc");
        $menu = json_encode($menu);
        $this->assign("menu", $menu);

        $product = D("Product")->getProductList(array("status" => array("neq", -1)), true, "recommend desc,rank desc", 0, 0, 0, session("userId"));
        $product = json_encode($product);
        $this->assign("product", $product);


        $ads = D("Ads")->getAdsList(array(), true);
        $ads = json_encode($ads);
        $this->assign("ads", $ads);
        $this->display();
    }

    public function init()
    {
        $data = array();
        $data["config"] = D("Config")->getConfig();
        $data["adsList"] = D("Ads")->getAdsList(array(), true);
        $data["menuList"] = D("Menu")->getMenuList(array(), true);
        $data["productList"] = D("Product")->getProductList(array(), true);
        $this->ajaxReturn($data);
    }
}